package com.ruoyi.web.controller.config;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.SpecialEquipmentAccount;
import com.ruoyi.system.entity.TargetManage;
import com.ruoyi.system.service.SpecialEquipmentAccountService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 特种设备台账(SpecialEquipmentAccount)表控制层
 *
 * @author makejava
 * @since 2023-03-20 16:41:12
 */
@RestController
@RequestMapping("specialEquipmentAccount")
public class SpecialEquipmentAccountController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private SpecialEquipmentAccountService specialEquipmentAccountService;

    @GetMapping("/list")
    public TableDataInfo queryByPage(SpecialEquipmentAccount specialEquipmentAccount) {
        startPage();
        List<SpecialEquipmentAccount> list = specialEquipmentAccountService.queryAll(specialEquipmentAccount);
        return getDataTable(list);
    }

    /**
     * 分页查询
     *
     * @param specialEquipmentAccount 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<SpecialEquipmentAccount>> queryByPage(SpecialEquipmentAccount specialEquipmentAccount, PageRequest pageRequest) {
        return ResponseEntity.ok(this.specialEquipmentAccountService.queryByPage(specialEquipmentAccount, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<SpecialEquipmentAccount> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.specialEquipmentAccountService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param specialEquipmentAccount 实体
     * @return 新增结果
     */
    @PostMapping("add")
    @PreAuthorize("@ss.hasPermi('specialEquipmentAccount:add')")
    public ResponseEntity<SpecialEquipmentAccount> add(@Validated @RequestBody SpecialEquipmentAccount specialEquipmentAccount) {
        return ResponseEntity.ok(this.specialEquipmentAccountService.insert(specialEquipmentAccount));
    }

    /**
     * 编辑数据
     *
     * @param specialEquipmentAccount 实体
     * @return 编辑结果
     */
    @PutMapping("edit")
    @PreAuthorize("@ss.hasPermi('specialEquipmentAccount:edit')")
    public ResponseEntity<SpecialEquipmentAccount> edit(@Validated @RequestBody SpecialEquipmentAccount specialEquipmentAccount) {
        return ResponseEntity.ok(this.specialEquipmentAccountService.update(specialEquipmentAccount));
    }

    /**
     * 删除数据
     *
     * @param specialEquipmentAccount 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete")
    @PreAuthorize("@ss.hasPermi('specialEquipmentAccount:delete')")
    public ResponseEntity<Boolean> deleteById(@Validated @RequestBody SpecialEquipmentAccount specialEquipmentAccount) {
        return ResponseEntity.ok(this.specialEquipmentAccountService.deleteById(specialEquipmentAccount.getId()));
    }

}

